<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>模拟var的块级作用域</title>
</head>
<body>
    
</body>
<script>
    for(var i = 0; i <= 3; i++){
        (function(j){
            //var是有函数作用域的
            setTimeout(function(){
              console.log(j);
           }, 1000) /// 0,1,2,3;
        })(i); //立即执行函数相当于在每次for循环之后都生成了一个块级作用域有自己的i  相当于let
    }
</script>
</html>